package frontend;


import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.UIManager;

import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;


//VS4E -- DO NOT REMOVE THIS LINE!
public class Index extends JFrame {


	//VARIABLES
	private static final long serialVersionUID = 1L;
	private JButton newGameButton;
	private JButton vocaloidsButton;
	private JButton gameRulesButton;
	private JButton exitGameButton;
	private JLabel backgroundImage;
	private static final String PREFERRED_LOOK_AND_FEEL = "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";


	//CONSTRUCTOR/S
	public Index() {
		initComponents();
	}

	private void initComponents() {
		setTitle("Monopoly - Vocaloids Edition");
		setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/icon.gif")));
		setResizable(false);
		ToolTipManager.sharedInstance().setInitialDelay(0);
		setLayout(new GroupLayout());
		add(initNewGameButton(), new Constraints(new Leading(36, 98, 6, 6), new Leading(141, 10, 10)));
		add(initVocaloidsButton(), new Constraints(new Leading(36, 98, 6, 6), new Leading(181, 6, 6)));
		add(initGameRulesButton(), new Constraints(new Leading(36, 6, 6), new Leading(219, 10, 10)));
		add(initExitGameButton(), new Constraints(new Leading(36, 98, 6, 6), new Leading(255, 10, 10)));
		add(initBackgroundImage(), new Constraints(new Leading(0, 12, 12), new Leading(0, 12, 12)));
		setSize(500, 390);
	}

	private JButton initNewGameButton() {
		if (newGameButton == null) {
			newGameButton = new JButton();
			newGameButton.setText("New Game");
			newGameButton.addActionListener(new ActionListener() {
	
				public void actionPerformed(ActionEvent event) {
					newGameButtonActionActionPerformed(event);
				}
			});
		}
		return newGameButton;
	}
	private JButton initVocaloidsButton() {
		if (vocaloidsButton == null) {
			vocaloidsButton = new JButton();
			vocaloidsButton.setText("Vocaloids?");
			vocaloidsButton.setToolTipText("Under Construction");
			vocaloidsButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent event) {
					vocaloidsButtonActionActionPerformed(event);
				}
			});
		}
		return vocaloidsButton;
	}
	private JButton initGameRulesButton() {
		if (gameRulesButton == null) {
			gameRulesButton = new JButton();
			gameRulesButton.setText("Game Rules");
			gameRulesButton.setToolTipText("Under Construction");
			gameRulesButton.addActionListener(new ActionListener() {
	
				public void actionPerformed(ActionEvent event) {
					gameRulesButtonActionActionPerformed(event);
				}
			});
		}
		return gameRulesButton;
	}
	private JButton initExitGameButton() {
		if (exitGameButton == null) {
			exitGameButton = new JButton();
			exitGameButton.setText("Exit");
			exitGameButton.addActionListener(new ActionListener() {
	
				public void actionPerformed(ActionEvent event) {
					exitGameButtonActionActionPerformed(event);
				}
			});
		}
		return exitGameButton;
	}

	private JLabel initBackgroundImage() {
		if (backgroundImage == null) {
			backgroundImage = new JLabel();
			backgroundImage.setIcon(new ImageIcon(getClass().getResource("/images/background/Index.jpg")));
		}
		return backgroundImage;
	}

	private static void installLnF() {
		try {
			String lnfClassname = PREFERRED_LOOK_AND_FEEL;
			if (lnfClassname == null)
				lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
			UIManager.setLookAndFeel(lnfClassname);
		} catch (Exception e) {
			System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
					+ " on this platform:" + e.getMessage());
		}
	}


	/**
	 * Main entry of the class.
	 * Note: This class is only created so that you can easily preview the result at runtime.
	 * It is not expected to be managed by the designer.
	 * You can modify it as you like.
	 */
	public static void main(String[] args) {
		installLnF();
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				Index frame = new Index();
				frame.setDefaultCloseOperation(Index.EXIT_ON_CLOSE);
				frame.setTitle("Index");
				frame.getContentPane().setPreferredSize(frame.getSize());
				frame.pack();
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
			}
		});
	}

	//ACTION EVENTS
	private void newGameButtonActionActionPerformed(ActionEvent event) {
		ChooseToken chooseToken = new ChooseToken();
		chooseToken.setVisible(true);
		this.dispose();
	}
	private void vocaloidsButtonActionActionPerformed(ActionEvent event) {
		JOptionPane.showMessageDialog(null, "This feature is still under construction.", "Under Construction", JOptionPane.PLAIN_MESSAGE);
	}
	private void gameRulesButtonActionActionPerformed(ActionEvent event) {
		JOptionPane.showMessageDialog(null, "This feature is still under construction.", "Under Construction", JOptionPane.PLAIN_MESSAGE);
	}
	private void exitGameButtonActionActionPerformed(ActionEvent event) {
		this.dispose();
	}
}
